package org.example.controller.iim;

import jakarta.annotation.Resource;
import org.example.domain.Result;
import org.example.domain.iim.Interfaces;
import org.example.mapper.InterfacesMapper;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @Author: whopxx
 * @CreateTime: 2025-01-06
 */
@RestController
@RequestMapping("/interfaces")
public class InterfacesController {

    @Resource
    private InterfacesMapper interfacesMapper;

    // pid: 项目id
    @GetMapping("/list")
    public Result list(@RequestParam Integer pid) {
        List<Interfaces> interfaces = interfacesMapper.selectByPid(pid);
        return Result.success(interfaces);
    }

    @PostMapping
    public Result add(@RequestBody Interfaces interfaces, @RequestParam Integer pid) {
        interfaces.setProjectId(pid);
        interfacesMapper.insert(interfaces);
        return Result.success();
    }


    @PutMapping
    public Result update(@RequestBody Interfaces interfaces,@RequestParam Integer pid) {
        interfaces.setProjectId(pid);
        interfacesMapper.updateById(interfaces);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(@RequestParam Integer id,@RequestParam Integer pid) {
        interfacesMapper.deleteById(id);
        return Result.success();
    }
}
